#include <iostream>
#include <vector>

#include "common_list.h"

using namespace std;

bool is_cycle(ListNode *head) {
    ListNode *fast, *slow;
    fast = slow = head;
    while (fast) {
        fast = fast->next->next;
        slow = slow->next;
        if (fast == slow) {
            return true;
        }
    }
    return false;
}

int main(void) {
    int val[] = {1, 2, 2, 1};
    cout << "(判断链表有没有环)" << endl;

    ListNode *head = generate_list_val(4, val);
    cout << "输出链表" << endl;
    print_list(head);
    if (is_cycle(head)) {
        cout << "有回环" << endl;
    } else {
        cout << "无回环" << endl;
    }
    return 0;
}